package com.flymobi.admin;

import java.util.List;

import com.flymobi.fw.modules.SM;
import com.flymobi.po.Manager;
import com.flymobi.po.SysMenu;
import com.flymobi.util.C;
import com.flymobi.util.WebContext;

/**
 * 
 * 
 * Title:
 * 
 * Description:
 * 
 * Copyright: Copyright (c) 2008
 * 
 * @author haoxz11
 * @created Oct 21, 2008 11:16:42 AM
 * @version $Id: SysMenuAction.java,v 1.1 2010/04/09 03:27:09 airsou Exp $
 */
public class SysMenuAction extends WebAction {
	private SysMenu sysMenu;
	private String fid;

	/**
	 * @return the fid
	 */
	public String getFid() {
		return fid;
	}

	/**
	 * @param fid the fid to set
	 */
	public void setFid(String fid) {
		this.fid = fid;
	}

	/**
	 * @return the sysMenu
	 */
	public SysMenu getSysMenu() {
		return this.sysMenu;
	}

	/**
	 * @param sysMenu
	 *            the sysMenu to set
	 */
	public void setSysMenu(SysMenu sysMenu) {
		this.sysMenu = sysMenu;
	}

	/**
	 * Comment for <code>serialVersionUID</code>
	 */
	private static final long serialVersionUID = 1L;

	@Override
	public String webProcess(WebContext context, Manager manager) {
		if ("add".equals(method)) {
			List<SysMenu> sysMenuList=SM.SysMenuService.list(C.SYS_MENU.FATHER);
			context.put("sysMenuList", sysMenuList);
			return "edit";
		} else if ("edit".equals(method)) {
			SysMenu sysMenu = SM.SysMenuService.get(id);
			List<SysMenu> sysMenuList=SM.SysMenuService.list(C.SYS_MENU.FATHER);
			context.put("sysMenu", sysMenu);
			context.put("sysMenuList", sysMenuList);
			return "edit";
		} else if ("save".equals(method)) {
			SM.SysMenuService.save(this.sysMenu);
			context.put("rmsg", C.TEXT.SAVE_SUCCESS);
			//return "save";
			method = "list";
			return this.webProcess(context, manager);
		}else if ("delete".equals(method)) {
			SM.SysMenuService.delete(id);
			SM.SysPowerService.deleteByMenuId(id);
			context.put("rmsg", C.TEXT.DELETE_SUCCESS);
			method = "list";
			return this.webProcess(context, manager);
		}else if ("list".equals(method)) {
			List<SysMenu> sysMenuList = SM.SysMenuService.list(C.SYS_MENU.FATHER);
			for (SysMenu sysMenu : sysMenuList) {
				sysMenu.setSysMenuList(SM.SysMenuService.list(String.valueOf(sysMenu.getId())));
			}
			context.put("sysMenuList", sysMenuList);
			return "list";
		} else {
			method = "list";
			return this.webProcess(context, manager);
		}
	}

	/* (non-Javadoc)
	 * @see com.camel.admin.WebAction#getSysLog()
	 */
	@Override
	public String getSysLog() {
		// TODO Auto-generated method stub
		return null;
	}
}
